package com.cgsd.heyu.ui.info;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.library.utils.SystemUtil;
import com.cgsd.heyu.R;
import com.cgsd.heyu.common.CommonConfig;
import com.cgsd.heyu.common.UserModeConfig;
import com.cgsd.heyu.presenter.home.HomeContract;
import com.cgsd.heyu.ui.BaseActivity;
import com.cgsd.heyu.utils.SaveFileUtil;
import com.cgsd.heyu.utils.StatusBarUtil;
import com.cgsd.heyu.utils.ZxingUtils;

/**
 * @author xiaoxing
 * Description 分享推广
 * CreateData: 2021/1/26
 */
public class ShareSpreadActivity extends BaseActivity<HomeContract.Presenter> implements View.OnClickListener {
    private ImageView ivCode;
    private String url;
    private Bitmap bitmap;

    public static void actionStart(Activity activity){
        Intent intent = new Intent(activity,ShareSpreadActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_share_spread;
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void initView() {
        url = CommonConfig.getInstance().shareInviteUrl + "recommendMemberNo="+UserModeConfig.getInstance().memberNo;
        TextView tvUrl = findViewById(R.id.tv_url);
        tvUrl.setText(url);
        TextView tvCode = findViewById(R.id.tv_interview_code);
        tvCode.setText("你的注册邀请码："+UserModeConfig.getInstance().memberNo);
        ivCode = findViewById(R.id.iv_qr_code);

        findViewById(R.id.tv_copy).setOnClickListener(this);
        findViewById(R.id.tv_save_image).setOnClickListener(this);
    }

    @Override
    protected void initData() {
        bitmap = ZxingUtils.createQRCode(url,500,2);

        ivCode.setImageBitmap(bitmap);
    }

    @Override
    protected void setStatusBar() {
        StatusBarUtil.fullBar(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tv_copy){
            SystemUtil.copyStr(this,url);
            showToast("复制成功");
        }else if (v.getId() == R.id.tv_save_image){
            SaveFileUtil.saveBitmap(this,bitmap);
            showToast("保存成功");
        }
    }
}
